package com.oceantrader.sale.commons.pojo;

import com.xuesinuo.xtool.Np;

import io.vertx.core.MultiMap;
import lombok.Data;

/** 分页公共参数 */
@Data
public abstract class PageParam implements SearchParam {
    /** 页码 */
    private Integer pageNum;
    /** 每页条数 */
    private Integer pageSize;

    public Integer getLimit1() {
        if (pageNum == null || pageSize == null) {
            return null;
        }
        return (this.pageNum - 1) * this.pageSize;
    }

    public Integer getLimit2() {
        if (pageNum == null || pageSize == null) {
            return null;
        }
        return this.pageSize;
    }

    @Override
    public void putMultiMap(MultiMap multiMap) {
        this.pageNum = Np.i(multiMap.get("pageNum")).x(x -> Integer.parseInt(x)).o();
        this.pageSize = Np.i(multiMap.get("pageSize")).x(x -> Integer.parseInt(x)).o();
    }
}